package com.yz.jdd.module.scan.view;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.yz.jdd.R;
import com.yz.jdd.base.MyApplication;
import com.yz.jdd.base.activity.BaseActivity;
import com.yz.jdd.base.utils.BaseConfigs;
import com.yz.jdd.base.utils.PreferencesUtils;
import com.yz.jdd.webview.Router;

public class InputCodeActivity extends BaseActivity implements View.OnClickListener {

    TextView topBack;

    TextView topTitle;

    Button verify_code;
    EditText input_code;

    String shopName;
    String shopId;

    private TextWatcher textWatcher = new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            if (TextUtils.isEmpty(s.toString())) {
                verify_code.setEnabled(false);
                return;
            }

            String sCode = input_code.getText().toString();
            if (!TextUtils.isEmpty(sCode)) {
                verify_code.setEnabled(true);
            } else {
                verify_code.setEnabled(false);
            }
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_input_code);
        initView();
    }

    void initView() {
        shopId= PreferencesUtils.getString(MyApplication.application, BaseConfigs.PREF_EVOUCHER_SHOPID);
        shopName=PreferencesUtils.getString(MyApplication.application, BaseConfigs.PREF_EVOUCHER_SHOPNAME);
        topBack = findViewById(R.id.top_back);
        topBack.setVisibility(View.VISIBLE);
        topBack.setOnClickListener(this);
        topTitle = findViewById(R.id.top_title);
        topTitle.setText("电子券核销");
        verify_code = findViewById(R.id.verify_code);
        verify_code.setOnClickListener(this);

        input_code=findViewById(R.id.input_code);
        input_code.addTextChangedListener(textWatcher);

    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.top_back) {
            finish();
        } else if (view.getId() == R.id.verify_code) {
            Router.startCancelVerifi(InputCodeActivity.this, shopId,shopName,"0",input_code.getText().toString().trim());

        }
    }
}
